package ModelLayer;


public class BattleCharacter {
	public static final int WARRIOR = 0;
	public static final int MAGE = 1;
	public static final int THIEF = 2;
	
	private int characterType;
	
	private String name;
	
	private int baseMaxHealth;
	private int baseMaxMana;
	private int baseStrength;
	private int baseDefense;
	private int baseSpeed;
	private int baseMagic;
	
	private int maxHealth;
	private int maxMana;
	private int strength;
	private int defense;
	private int speed;
	private int magic;
	
	private int currentHealth;
	private int currentMana;
	private int level;
	private int xp;
	
	//private Item headEquip = new Item(0);
	//private Item chestEquip = new Item (0);
	//private Item weaponEquip = new Item (0);
	
	public static final int actionBarMax = 5000;
	private int currentActionBar;
	
	public BattleCharacter(int characterType) {
		this.characterType = characterType;
		
		switch (characterType) {
		case WARRIOR:
			name = "Warrior";
			break;
		case MAGE:
			name = "Mage";
			break;
		case THIEF:
			name = "Thief";
			break;
		}
	}
	
	/*public void equipHead(int ref) {
		Item item = new Item(ref);
		if (item.getUsable() != 1)
			System.out.println("You can't wear that on your head!");
		else {
		
			if (headEquip.isItem())
				unequipHead();
			
			headEquip = item;			
			updateStats();
			Inventory.takeItem(item);
		}
	}
	
	public void equipChest(int ref) {
		Item item = new Item(ref);
		if (item.getUsable() != 2)
			System.out.println("You can't wear that on your chest!");
		else {
			
			if (chestEquip.isItem())
				unequipChest();
		
			chestEquip = item;
			updateStats();
			Inventory.takeItem(item);
		}
	}
	
	public void equipWeapon(int ref) {
		Item item = new Item(ref);
		if (item.getUsable() != 3)
			System.out.println("You can't wield that!");
		else {
			
			if (weaponEquip.isItem())
				unequipWeapon();
		
			weaponEquip = item;
			updateStats();
			Inventory.takeItem(item);
		}
	}

	public Item getHeadEquip() {
		return headEquip;
	}

	public Item getChestEquip() {
		return chestEquip;
	}

	public Item getWeaponEquip() {
		return weaponEquip;
	}
	
	public void unequipHead() {
		if(!headEquip.isItem()) {
			System.out.println("Nothing equipped!");
		}
		
		else {
			currentHealth -= headEquip.getMaxHealth();
			currentMana -= headEquip.getMaxMana();
			
			updateStats();
			Inventory.addItem(headEquip);
			headEquip = new Item(0);
		}
	}
	
	public void unequipChest() {
		if(!chestEquip.isItem()) {
			System.out.println("Nothing equipped!");
		}
		
		else {
			currentHealth -= chestEquip.getMaxHealth();
			currentMana -= chestEquip.getMaxMana();
			
			updateStats();
			Inventory.addItem(chestEquip);
			chestEquip = new Item(0);
		}
	}
	
	public void unequipWeapon() {
		if(!weaponEquip.isItem()) {
			System.out.println("Nothing equipped!");
		}
		
		else {
			currentHealth -= weaponEquip.getMaxHealth();
			currentMana -= weaponEquip.getMaxMana();
			
			updateStats();
			Inventory.addItem(weaponEquip);
			weaponEquip = new Item(0);
		}
	}
	
	public void updateStats() {
		maxHealth = baseMaxHealth + headEquip.getMaxHealth() + chestEquip.getMaxHealth() + weaponEquip.getMaxHealth();
		maxMana = baseMaxMana + headEquip.getMaxMana() + chestEquip.getMaxMana() + weaponEquip.getMaxMana();
		strength = baseStrength + headEquip.getStrength() + chestEquip.getStrength() + weaponEquip.getStrength();
		defense = baseDefense + headEquip.getDefense() + chestEquip.getDefense() + weaponEquip.getDefense();
		speed = baseSpeed + headEquip.getSpeed() + chestEquip.getSpeed() + weaponEquip.getSpeed();
		magic = baseMagic + headEquip.getMagic() + chestEquip.getMagic() + weaponEquip.getMagic();
	}
	
	public void levelUp() {
		switch (characterType) {
		case WARRIOR:
			level++;
			setXP(0);
			
			currentHealth += (level * 5);
			currentMana += (level * 3);
			baseMaxHealth += (level * 5);
			baseMaxMana += (level * 3);
			baseStrength += (level * 3);
			baseDefense += (level * 4);
			baseSpeed += (level * 2);
			baseMagic += (level * 1);
			updateStats();
			
			System.out.println("Warrior leveled up.");
			break;
		case MAGE:
			level++;
			setXP(0);
			
			currentHealth += (level * 2);
			currentMana += (level * 4);
			baseMaxHealth += (level * 2);
			baseMaxMana += (level * 4);
			baseStrength += (level * 1);
			baseDefense += (level * 2);
			baseSpeed += (level * 3);
			baseMagic += (level * 5);
			updateStats();
			
			System.out.println("Mage leveled up.");
			break;
		case THIEF:
			level++;
			setXP(0);
			
			currentHealth += (level * 3);
			currentMana += (level * 1);
			baseMaxHealth += (level * 3);
			baseMaxMana += (level * 1);
			baseStrength += (level * 4);
			baseDefense += (level * 3);
			baseSpeed += (level * 5);
			baseMagic += (level * 2);
			updateStats();
			
			System.out.println("Thief leveled up.");
			break;
		}
	}*/
	
	public void incrementActionBar() {
		currentActionBar += speed;
	}
	
	public int getCurrentActionBar() {
		return currentActionBar;
	}
	
	public void resetActionBar() {
		currentActionBar = 0;
	}
	
	public void newGameStats() {
		switch (characterType) {
		case WARRIOR:
			baseMaxHealth = 50;
			baseMaxMana = 30;
			baseStrength = 6;
			baseDefense = 8;
			baseSpeed = 4;
			baseMagic = 2;
			
			maxHealth = baseMaxHealth;
			maxMana = baseMaxMana;
			strength = baseStrength;
			defense = baseDefense;
			speed = baseSpeed;
			magic = baseMagic;
			
			currentHealth = maxHealth;
			currentMana = maxMana;
			level = 1;
			xp = 0;
			System.out.println("Warrior stats initialized.");
			break;
		case MAGE:
			baseMaxHealth = 20;
			baseMaxMana = 40;
			baseStrength = 2;
			baseDefense = 4;
			baseSpeed = 6;
			baseMagic = 10;
			
			maxHealth = baseMaxHealth;
			maxMana = baseMaxMana;
			strength = baseStrength;
			defense = baseDefense;
			speed = baseSpeed;
			magic = baseMagic;
			
			currentHealth = maxHealth;
			currentMana = maxMana;
			level = 1;
			xp = 0;
			System.out.println("Mage stats initialized.");
			break;
		case THIEF:
			baseMaxHealth = 30;
			baseMaxMana = 10;
			baseStrength = 8;
			baseDefense = 6;
			baseSpeed = 10;
			baseMagic = 4;
			
			maxHealth = baseMaxHealth;
			maxMana = baseMaxMana;
			strength = baseStrength;
			defense = baseDefense;
			speed = baseSpeed;
			magic = baseMagic;
			
			currentHealth = maxHealth;
			currentMana = maxMana;
			level = 1;
			xp = 0;
			System.out.println("Thief stats initialized.");
			break;
		}	
	}
	
	/*public int getXP() {
		return xp;
	}
	
	public void setXP(int x) {
		xp = x;
		if(xp >= level * 100)
			levelUp();
	}*/
	
	public int getLevel() {
		return level;
	}
	
	public void setLevel(int x) {
		level = x;
	}
	
	public int getCurrentHealth() {
		return currentHealth;
	}
	
	public void setCurrentHealth(int x) {
		currentHealth = x;
	}

	public int getMaxHealth() {
		return maxHealth;
	}
	
	public int getBaseMaxHealth() {
		return baseMaxHealth;
	}
	
	public void setMaxHealth(int x) {
		baseMaxHealth = x;
	}
	
	public int getCurrentMana() {
		return currentMana;
	}
	
	public void setCurrentMana(int x) {
		currentMana = x;
	}

	public int getMaxMana() {
		return maxMana;
	}
	
	public int getBaseMaxMana() {
		return baseMaxMana;
	}
	
	public void setMaxMana(int x) {
		baseMaxMana = x;
	}

	public int getStrength() {
		return strength;
	}
	
	public int getBaseStrength() {
		return baseStrength;
	}
	
	public void setStrength(int x) {
		baseStrength = x;
	}

	public int getDefense() {
		return defense;
	}
	
	public int getBaseDefense() {
		return baseDefense;
	}
	
	public void setDefense(int x) {
		baseDefense = x;
	}

	public int getSpeed() {
		return speed;
	}
	
	public int getBaseSpeed() {
		return baseSpeed;
	}
	
	public void setSpeed(int x) {
		baseSpeed = x;
	}

	public int getMagic() {
		return magic;
	}
	
	public int getBaseMagic() {
		return baseMagic;
	}
	
	public void setMagic(int x) {
		baseMagic = x;
	}
	
	public String getName() {
		return name;
	}
}
